package com.yxy.patient.utils;

import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import androidx.annotation.ColorRes;

import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.yxy.patient.Application;
import com.yxy.patient.widiget.GlideRoundTransform;

public class Views {
    private static final RequestOptions requestOptions = new RequestOptions().transform(new CenterCrop(), new RoundedCorners(20));
    private static final RequestOptions twoRoundedCornersTransform = new RequestOptions().transform(new CenterCrop(), new GlideRoundTransform(5));
    public final static int dp10 = dip2px(10);
    public final static int dp1 = dip2px(1);
    public final static int dp5 = dip2px(5);

    public static int dip2px(float dpValue) {
        float scale = Application.self.getResources().getDisplayMetrics().density;
        return (int) (dpValue * scale + 0.5f);
    }

    public static int sp2px(float spValue) {
        final float fontScale = Application.self.getResources().getDisplayMetrics().scaledDensity;
        return (int) (spValue * fontScale + 0.5f);
    }

    public static int getWidth() {
        DisplayMetrics outMetrics = new DisplayMetrics();
        ((WindowManager) (Application.self.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))).getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.widthPixels;
    }

    public static int getHeight() {
        DisplayMetrics outMetrics = new DisplayMetrics();
        ((WindowManager) (Application.self.getApplicationContext().getSystemService(Context.WINDOW_SERVICE))).getDefaultDisplay().getMetrics(outMetrics);
        return outMetrics.heightPixels;
    }

    public static int getColor(@ColorRes int resId) {
        return Application.self.getResources().getColor(resId);
    }

    public static RequestOptions roundedCornersTransform() {
        return requestOptions;
    }

    public static RequestOptions twoRoundedCornersTransform() {
        return twoRoundedCornersTransform;
    }
}
